<template>
  <div id="evaluate">
    <div class="evaluate-top">
      <div class="evaluate-top-left">
        <div class="evaluate-top-left-score">4.5</div>
        <div class="evaluate-top-left-text">综合评分</div>
        <div class="evaluate-top-left-bottom">高于周边商家69.2%</div>
      </div>
      <div class="evaluate-top-right">
        <div class="rate-item">
          <span>总体</span>
          <van-rate
            v-model="value1"
            :size="17"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            allow-half
          />
        </div>
        <div class="rate-item">
          <span>口味</span>
          <van-rate
            v-model="value2"
            :size="17"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            allow-half
          />
        </div>
        <div class="rate-item">
          <span>包装</span>
          <van-rate
            v-model="value3"
            :size="17"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            allow-half
          />
        </div>
      </div>
    </div>
    <div class="evaluate-bot">
      <ul>
        <li
          v-for="item in items"
          :key="item"
          :class="{ green: item === activeItem }"
          @click="setActiveItem(item)"
        >
          {{ item }}
        </li>
      </ul>
      <div class="evaluate-context">
        <div
          class="context-item"
          v-for="(item, index) in evaluateData"
          :key="index"
        >
          <div class="item-top">
            <img :src="item.avatar" alt="" />
            <div class="info">
              <div class="info-top">
                <span>{{ item.username }}</span>
                <span>{{ item.rateTime }}</span>
              </div>
              <div class="info-bot">
                <van-rate
                  v-model="item.score"
                  :size="14"
                  color="#ffd21e"
                  void-icon="star"
                  void-color="#eee"
                  allow-half
                />
                <span>{{ item.deliveryTime }}分钟送达</span>
              </div>
            </div>
          </div>
          <div class="item-bot">{{ item.text }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { getShopRatings } from "@/api/index.js";
const value1 = ref(4.5);
const value2 = ref(4.5);
const value3 = ref(5);
const items = ["全部", "满意", "不满意"];
const activeItem = ref("全部");
const evaluateData = ref([]);
const resData = ref([]);

const setActiveItem = (item) => {
  activeItem.value = item;
  if (item === "满意") {
    evaluateData.value = resData.value.filter((r) => {
      return r.rateType === 0;
    });
  } else if (item === "不满意") {
    evaluateData.value = resData.value.filter((r) => {
      return r.rateType === 1;
    });
  } else {
    evaluateData.value = resData.value;
  }
};
onMounted(async () => {
  const res = await getShopRatings();
  console.log("🚀 ~ onMounted ~ res:", res.data);
  resData.value = res.data;
  evaluateData.value = res.data;
});
</script>

<style scoped lang="less">
#evaluate {
  font-size: 16px;
}
.evaluate-top {
  display: flex;
  align-items: center;
  height: 100px;
  width: 100%;
  border-bottom: 0.01rem solid #ccc;
  .evaluate-top-left {
    border-right: 0.01rem solid #ccc;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 50%;
    .evaluate-top-left-score {
      font-size: 26px;
      color: #f90;
    }
    .evaluate-top-left-text {
      font-weight: 900;
    }
    .evaluate-top-left-bottom {
      margin-top: 5px;
      font-size: 12px;
      color: #999;
    }
  }
  .evaluate-top-right {
    height: 80%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: space-between;
    width: 50%;
    font-size: 14px;
    font-weight: 900;
    .rate-item {
      display: flex;
      align-items: center;
      span {
        margin-right: 5px;
      }
    }
  }
}

.evaluate-bot {
  ul {
    width: 95%;
    margin: 10px auto;
    height: 22px;
    background: rgb(255, 255, 255);
    display: flex;
    justify-content: space-around;
    align-items: center;
    cursor: pointer; /* 添加手型指针 */
    li {
      height: 100%;
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex: 1;
      color: #238444;
      border: 0.01rem solid #238444;
    }
    .green {
      background: #238444;
      color: #fff;
    }
  }
  .context-item {
    font-size: 13px;
    margin: auto;
    width: 95%;
    height: 100px;
    border-top: 1px solid #e5e5e5;
    border-bottom: 1px solid #e5e5e5;
    .item-top {
      height: 50%;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      img {
        height: 40px;
        width: 40px;
        border-radius: 50%;
        margin-left: 10px;
      }
      .info {
        width: 80%;
        height: 100%;
        .info-top {
          height: 50%;
          width: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
        }
        .info-bot {
          height: 50%;
          display: flex;
          align-items: center;
          span {
            font-size: 12px;
            color: #adadad;
            margin-left: 4px;
            margin-top: 2px;
          }
        }
      }
    }
    .item-bot {
      font-size: 13px;
      margin-left: 57px;
      height: 50%;
      width: 80%;
    }
  }
}
</style>
